package com.baiku.sanhos.utils.model.util;

import org.apache.poi.ss.usermodel.*;

/**
 * 自定义字体样式类
 */
public class ElsxFontStyle {
    /**
     * 在单元格中设置样式  cell.setCellStyle(style);
     *
     * @param workbook Workbook workbook = new XSSFWorkbook(inputStream))
     * @param fontSize 字体大小
     * @return CellStyle返回一个类型 字体大小,加上居中对齐
     */
    public static CellStyle fontTypeCenter(Workbook workbook, Short fontSize) {
        CellStyle style = fontType(workbook, fontSize);
        // 设置文字居中对齐
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        return style;
    }

    /**
     * 在单元格中设置样式  cell.setCellStyle(style);
     *
     * @param workbook Workbook workbook = new XSSFWorkbook(inputStream))
     * @param fontSize 字体大小
     * @return CellStyle返回一个类型 字体大小,加上左对齐
     */
    public static CellStyle fontTypeLeft(Workbook workbook, Short fontSize) {
        CellStyle style = fontType(workbook, fontSize);
        // 设置文字居中对齐
        style.setAlignment(HorizontalAlignment.LEFT);
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        return style;
    }

    /**
     * 在单元格中设置样式  cell.setCellStyle(style);
     *
     * @param workbook Workbook workbook = new XSSFWorkbook(inputStream))
     * @param fontSize 字体大小
     * @return CellStyle返回一个类型 字体大小
     */
    public static CellStyle fontType(Workbook workbook, Short fontSize) {
        CellStyle style = workbook.createCellStyle();
        Font font = workbook.createFont();

        // 设置字体大小
        font.setFontHeightInPoints(fontSize);
        style.setFont(font);

        return style;
    }
}
